<!-- 跳转支付宝二维码 -->
<template>
	<view>
		<uni-popup ref="popup" background-color="#fff">
			<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
				<view class="img-box">
					<image :src="imgUrl" mode="widthFix" style="width: 400rpx; height: 400rpx;"></image>
				</view>
				<button @click="saveImg">保存图片到相册</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		name: "payCode",
		props: {
			imgUrl: ""
		},
		data() {
			return {
				// img: require('../../static/images/paycode.png')
			};
		},
		methods: {
			open() {
				this.$refs.popup.open('bottom')
			},
			saveImg(){
				if(this.imgUrl==="") return
				uni.downloadFile({
					url: this.imgUrl,
					success: res => {
						if(res.statusCode === 200) {
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: (result) => {
									uni.showToast({
										title: '保存成功',
										icon: 'none'
									})
								},
								fail: (err) => {
									uni.showToast({
										title: '保存失败,请截图保存',
										icon: 'none'
									})
								}
							})
						}
					},
					fail: (error) => {
						uni.showToast({
							title: '保存失败',
							icon: 'none'
						})
					}
				})
			},
		}
	}
</script>

<style>
.popup-content{
	height: 60vh;
	text-align: center;
	padding: 30rpx 0;
}
.img-box{
	padding: 40rpx 0;
}
</style>
